﻿using UnityEngine;
using System.Collections;
using System.Collections.Generic;

public class EnemyManager : Singleton<EnemyManager> 
{
	protected EnemyManager () {}

	[System.Serializable]
	public class EnemyData
	{
		public Enemy.EnemyType m_EnemyType;
		public GameObject m_Prefab;
	}

	public List<EnemyData> m_EnemyDatasList;

	private Dictionary<Enemy.EnemyType, GameObject> m_EnemyDatas;
	public GameObject GetPrefabByEnemyType(Enemy.EnemyType i_EnemyType)
	{
		if(m_EnemyDatas.ContainsKey(i_EnemyType))
		{
			return m_EnemyDatas[i_EnemyType];
		}

		return null;
	}

	[HideInInspector]
	public Dictionary<LevelPartInfo, int> m_EnemiesPerLevel;

	private int m_EnemiesCounter;
	public int EnemiesCounter
	{
		get { return m_EnemiesCounter; }
		set { m_EnemiesCounter = value; }
	}

	protected override void Awake()
	{
		base.Awake();

		m_EnemyDatas = new Dictionary<Enemy.EnemyType, GameObject>();
		for(int i = 0; i < m_EnemyDatasList.Count; i++)
		{
			m_EnemyDatas.Add (m_EnemyDatasList[i].m_EnemyType, m_EnemyDatasList[i].m_Prefab);
		}

		m_EnemiesPerLevel = new Dictionary<LevelPartInfo, int>();
	}

	private void Update()
	{		
	}

	#region REGISTRATION
	public void RegisterEnemyPerLevel(LevelPartInfo i_PartInfo)
	{
		if(m_EnemiesPerLevel.ContainsKey(i_PartInfo))
		{
			m_EnemiesPerLevel[i_PartInfo]++;
		}
		else
		{
			m_EnemiesPerLevel.Add (i_PartInfo, 1);
		}
	}

	public void UnregisterEnemyPerLevel(LevelPartInfo i_PartInfo)
	{
		if(m_EnemiesPerLevel.ContainsKey(i_PartInfo))
		{
			m_EnemiesPerLevel[i_PartInfo]--;

			if(m_EnemiesPerLevel[i_PartInfo] == 0)
			{
				m_EnemiesPerLevel.Remove(i_PartInfo);

				if(i_PartInfo.m_Type != LevelManager.LevelType.FORWARDONLY)
				{
					LevelManager.Instance.m_LockCheck = false;
				}
			}
		}
	}
	#endregion


}
